﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Workflow.ComponentModel

Namespace System.Workflow.ComponentModel.Design
    Friend Class ExtenderHelpers
        ' Methods
        Friend Shared Sub FilterDependencyProperties(ByVal serviceProvider As IServiceProvider, ByVal activity As Activity)
            Dim service As IExtenderListService = [TryCast](serviceProvider.GetService(GetType(IExtenderListService)),IExtenderListService)
            If (Not service Is Nothing) Then
                Dim dictionary As New Dictionary([Of] String, DependencyProperty)
                Dim property As DependencyProperty
                For Each property In activity.MetaDependencyProperties
                    dictionary.Add([property].Name, [property])
                Next
                Dim list As New List([Of] String)
                Dim provider As IExtenderProvider
                For Each provider In service.GetExtenderProviders
                    If Not provider.CanExtend(activity) Then
                        Dim customAttributes As ProvidePropertyAttribute() = [TryCast](provider.GetType.GetCustomAttributes(GetType(ProvidePropertyAttribute), True),ProvidePropertyAttribute())
                        Dim attribute As ProvidePropertyAttribute
                        For Each attribute In customAttributes
                            list.Add(attribute.PropertyName)
                        Next
                    End If
                Next
                Dim str As String
                For Each str In list
                    If dictionary.ContainsKey(str) Then
                        activity.RemoveProperty(dictionary.Item(str))
                    End If
                Next
            End If
        End Sub

    End Class
End Namespace

